﻿namespace Tomato.Allure
{
	internal class VisualStudioImpl : Tomato.Allure.IVisualStudio
	{
		private EnvDTE80.DTE2 m_instance;

		public Tomato.Allure.ISolution ActiveSolution
		{
			get
			{
				if( m_instance.Solution != null )
				{
					return new SolutionImpl( m_instance.Solution );
				}

				return null;
			}
		}

		public Tomato.Allure.IDocument ActiveDocument
		{
			get 
			{
				if( m_instance.ActiveDocument != null )
				{
					return new DocumentImpl( m_instance.ActiveDocument );
				}

				return null;
			}
		}

		public Tomato.Allure.IWindow ActiveWindow
		{
			get 
			{
				if( m_instance.ActiveWindow != null )
				{
					return new WindowImpl( m_instance.ActiveWindow );
				}

				return null;
			}
		}

		public Tomato.Allure.IWindow MainWindow
		{
			get
			{
				if( m_instance.MainWindow != null )
				{
					return new WindowImpl( m_instance.MainWindow );
				}

				return null;
			}
		}

		public Tomato.Allure.IOutputWindow OutputWindow
		{
			get
			{
				EnvDTE.OutputWindow outputWindow = ( EnvDTE.OutputWindow )( m_instance.Windows.Item( EnvDTE.Constants.vsWindowKindOutput ).Object );
				if( outputWindow != null )
				{
					return new OutputWindowImpl( outputWindow );
				}

				return null;
			}
		}

		public Tomato.Allure.MDIType MDIType
		{
			get
			{
				switch( m_instance.DisplayMode )
				{
					case EnvDTE.vsDisplay.vsDisplayMDI: return Tomato.Allure.MDIType.MDIWindows;
				}

				return Tomato.Allure.MDIType.MDITabs;
			}
		}

		public Tomato.Allure.IDocuments OpenedDocuments
		{
			get
			{
				if( m_instance.Documents != null )
				{
					return new DocumentsImpl( m_instance.Documents );
				}

				return null;
			}
		}

		public Tomato.Allure.IWindows Windows
		{
			get
			{
				if( m_instance.Windows != null )
				{
					return new WindowsImpl( m_instance.Windows );
				}

				return null;
			}
		}

		public VisualStudioImpl( EnvDTE80.DTE2 instance )
		{
			m_instance = instance;
		}
	}
}
